package com.ymj.provider;

import com.ymj.netty.server.Server;
import com.ymj.provider.utils.SpringContextUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
/**
 *  @Description: 容器初始化完成后启动netty服务器
 *  @author: yanmj
 *  @Date: 2020-06-07
 */
@Component
public class ServerInit implements ApplicationListener<ContextRefreshedEvent> {

    /**
     * 容器初始化完成后执行
     * @param contextRefreshedEvent
     */
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        Server server = SpringContextUtils.getBean(Server.class);
        try {
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
